<%@ taglib prefix="c" uri="http://java.sun.com/jstl/core"%>
<%@ taglib prefix="form" uri="http://www.springframework.org/tags/form"%>

<%@page import="au.com.mason.propertyTracker.dto.Report"%>
<%@page import="java.util.Iterator"%>
<%@page import="java.util.List"%>

<table align="center" width="75%" cellpadding="5">
	<tr>
		<td><b>Suburb</b></td>
		<td><b>Month</b></td>
		<td><b>Year</b></td>
		<td><b>Bedrooms</b></td>
		<td><b>Listed</b></td>
		<td><b>With Price</b></td>
		<td><b>Sold/Removed</b></td>
		<td><b>Avg Price</b></td>
		<td><b>Avg Time</b></td>
		<td><b>Rentals</b></td>
		<td><b>Removed</b></td>
		<td><b>Avg Rent</b></td>
		<td><b>Avg Time</b></td>
	</tr>
	<c:forEach items="${reports}">
			<tr>
			<td rowspan="<s:property value="value.size" />" valign="top"><s:property value="key" /></td>
			<s:set name="previousMonth" value="" />
			<%int count = 0;%>
		<c:forEach items="${value}" var="record">
			<%if (count > 0) {%>
				<tr>
					<td></td>
			<%}%>
			<%if (pageContext.findAttribute("month").equals(pageContext.findAttribute("previousMonth"))) {%>
			<td colspan="2"></td>
			<%} else {%>
			<td><c:out value="${record.month}" /></td>
			<td><c:out value="${record.year}" /></td>			
			<% } %>
			<td><c:out value="${record.numberBedrooms}" /></td>
			<td><c:out value="${record.propertiesListed}" /></td>
			<td><c:out value="${record.propertiesListedWithPrice}" /></td>
			<td><c:out value="${record.propertiesSold}" /></td>
			<td><c:out value="${record.averagePrice}" /></td>
			<td><c:out value="${record.averagePropertyOnMarket}" /></td>
			<td><c:out value="${record.rentalsListed}" /></td>
			<td><c:out value="${record.renatalsRemoved}" /></td>
			<td><c:out value="${record.averageRent}" /></td>
			<td><c:out value="${record.averageRentalOnMarket}" /></td>
		</tr>
		<c:param name="previousMonth" value="month" />
		<%count++;%>	
		</c:forEach>
	</c:forEach>
</table>

</html>